<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        header {
            width: 100%;
            height: 44px;
            box-sizing: content-box;
            background-color: #5AC2FF;
        }

        .fixed {
            z-index: 999;
            position: fixed;
            top: 0;
            left: 0;
        }

        .icon-close {
            width: 22px;
            height: 22px;
            margin-right: 15px;
        }

        .img-bg {
            background-image: url("../../image/ui/bg_img.png");
            background-size: 100%;
            background-color: #5AC2FF;
            height: 468px;
            overflow: hidden;
        }

        .icon-complete {
            width: 22px;
            height: 22px;
            min-width: 22px;
            margin-right: 10px;
        }

        .text-title {
            font-size: 18px;
            font-weight: 500;
            color: #222224;
            line-height: 25px;
        }

        .icon-cube {
            width: 6px;
            height: 6px;
            min-width: 6px;
            margin: 0 9px;
        }

        .text-small {
            font-size: 12px;
            font-weight: 400;
            color: #222224;
            line-height: 17px;
        }

        .text-score {
            font-size: 45px;
            font-weight: 500;
            color: #FD9B43;
            text-align: center;
        }

        .box-white {
            background-color: #fff;
            border-radius: 10px 10px 0 0;
            margin-top: -248px;
        }

        .img-small {
            position: relative;
            top: -28px;
            display: block;
            width: 70px;
            height: 94px;
            border-radius: 5px;
            margin: 0 auto;
        }

        .text-name {
            font-size: 15px;
            font-weight: 500;
            color: #222224;
            line-height: 21px;
            text-align: center;
            margin-top: -14px;
        }

        .btn-orange {
            width: 96px;
            height: 36px;
            margin: 15px auto 0 auto;
            background: #FD9B43;
            border-radius: 20px;
            line-height: 36px;
            text-align: center;
            font-size: 14px;
            color: #fff;
        }

        .icon-unknown {
            width: 22px;
            height: 24px;
            min-width: 22px;
            margin: 0 9px;
        }

        .img-big {
            display: block;
            width: 167px;
            height: 220px;
            margin: 20px auto 0 auto;
            border-radius: 5px;
        }

        .img-avatar {
            position: relative;
            top: -28px;
            width: 84px;
            height: 84px;
            margin: 0 auto;
            border-radius: 50%;
        }

        .list-container {
            padding: 0 15px 15px 15px;
        }

        .text-caption {
            font-size: 16px;
            color: #222224;
            font-weight: 500;
            line-height: 22px;
            margin-top: 25px;
            margin-left: 15px;
        }

        .flex-wrap {
            flex-wrap: wrap;
            margin: 0 -7.5px;
        }

        .item-container {
            width: 50%;
            padding: 0 7.5px;
            margin-top: 15px;
        }

        .item-cover {
            display: block;
            width: 100%;
            height: 220px;
            border-radius: 5px;
        }

        .item-score {
            font-size: 15px;
            color: #222224;
            margin-top: 13px;
        }

        .text-orange {
            font-size: 16px;
            color: #FD9B43;
        }

        .text-unread {
            font-size: 12px;
            color: #BFBFBF;
            margin-top: 5px;
        }

        .fixed-bottom {
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 60px;
            padding: 10px 15px;
            background-color: #fff;
        }

        .fixed-bottom .btn {
            width: 100%;
            height: 40px;
            line-height: 40px;
            background: #FD9B43;
            color: #fff;
            font-size: 15px;
            text-align: center;
            border-radius: 20px;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <header class="fixed" data-flex="cross:center main:right">
            <img onclick="api.closeWin()" src="../../image/ui/close_white.png" alt="" class="icon-close">
        </header>
        <header></header>
        <div class="img-bg">
            <div style="margin-top: 56px;" data-flex="cross:center main:center">
                <img src="../../image/ui/complete.png" alt="" class="icon-complete">
                <div class="text-title">已完成阅读</div>
            </div>
            <div style="margin-top: 22px;" data-flex="cross:center main:center">
                <img src="../../image/ui/cube.png" alt="" class="icon-cube">
                <div class="text-small">平均得分</div>
                <img src="../../image/ui/cube.png" alt="" class="icon-cube">
            </div>
            <div class="text-score">{{ score.toFixed(0) }}</div>
        </div>
        <div class="box-white" v-if="index + 1 < listData.length">
            <img :src="currItem.pbookPic"
                alt="" class="img-small">
            <div class="text-name">{{currItem.pbookName}}</div>
            <div class="btn-orange" @click="handleRead(currItem,index)">重新阅读</div>
            <div style="margin-top: 40px;" data-flex="cross:center main:center">
                <img src="../../image/ui/unknown.png" alt="" class="icon-unknown">
                <div class="text-title">下一绘本</div>
                <img src="../../image/ui/unknown.png" alt="" class="icon-unknown">
            </div>
            <img :src="nextItem.pbookPic"
                alt="" class="img-big">
            <div class="text-name" style="margin-top: 11px;">{{nextItem.pbookName}}</div>
            <div class="btn-orange" @click="handleRead(nextItem, index + 1)">阅读绘本</div>
            <div style="height: 23px;"></div>
        </div>
        <div class="box-white" v-else>
            <img :src="report.appUserAvatar" alt="" class="img-avatar">
            <div class="text-name">{{report.appUserName}}的学习报告</div>
            <div class="text-caption">选集打分</div>
            <div class="list-container">
                <div class="flex-wrap" data-flex="main:justify">
                    <div class="item-container" v-for="item,_index in report.childCatalogList" @click="handleRead(listData[_index],_index)">
                        <div>
                            <img :src="item.pbookPic"
                                alt="" class="item-cover">
                            <div class="item-score">{{item.pbookName}}</div>
                            <div class="item-score">录音得分&nbsp;<span class="text-orange">{{item.scoreValue}}&nbsp;分</span></div>
                            <!-- <div class="text-unread" data-flex="cross:center main:justify">
                                2个页面未录音
                                <div class="text-orange" style="font-size: 12px;">去录音></div>
                            </div> -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div v-if="index + 1 == listData.length" style="height: 60px;background-color: #fff;"></div>
        <div v-if="index + 1 == listData.length" class="fixed-bottom">
            <div class="btn" @click="handleRead(listData[0], 0)">重新阅读</div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm, pageParam;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        pageParam = api.pageParam;
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                // 套集 id
                hbId: pageParam.hbId,
                // 所有集数
                listData: pageParam.info.listData,
                // 当前集数索引
                index: Number(pageParam.index),
                // 得分
                score: pageParam.score,
                // 最终报告
                report: {}
            },
            computed: {
                nextItem: function() {
                    var listData = this.listData;
                    var index = this.index;
                    if(index + 1 < listData.length) {
                        return listData[index + 1];
                    }
                },
                currItem: function() {
                    var listData = this.listData;
                    var index = this.index;
                    return listData[index];
                }
            }
        });
        if(vm.index + 1 == vm.listData.length) {
            getListData();
        }
    }

    // 获取最终学习报告
    function getListData() {
        var params = {
            id: vm.hbId
        };
        var url = 'stuPicture/findPictureBookPageStudentReport';
        var callback = function(data) {
            vm.report = data;
            var score = 0;
            var listData = vm.report.childCatalogList;
            listData.forEach(function(item, index) {
                score += Number(item.scoreValue);
            });
            vm.score = parseInt(score / listData.length);
        };
        POST(url, params, callback);
    }

    // 阅读
    function handleRead(item, index) {
        var params = {
            isBtn: false,
            btnName: '练习题',
            headerFn: 'headerFn',
            catalogId: item.catalogId,
            itemId: item.id,
            index: index,
            hbId: vm.hbId,
            info: pageParam.info,
            isConfigQuestion: item.isConfigQuestion,
            isActivate: pageParam.info.isActivate
        };
        fnOpenPublicWin(item.pbookName, 'video/hb_start', params);
    }
</script>

</html>